package com.example.demo.MessageController;

import com.example.demo.medol.MessageInfo;
import com.example.demo.service.MessageSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/message")
@RestController
public class MessageController {
    @Autowired
    private MessageSerivce serivce;
    //List<MessageInfo> messageInfos=new ArrayList<>();
    @RequestMapping("/publish")//发布留言
    public boolean publishMessage(MessageInfo messageInfo)
    {
        if(!StringUtils.hasLength(messageInfo.getFrom())
                ||!StringUtils.hasLength(messageInfo.getTo())
                ||!StringUtils.hasLength(messageInfo.getMessage()))
        {
            return false;
        }
        //添加
        serivce.addMessage(messageInfo);
        return true;
    }
    //查看留言
    @RequestMapping("/getMessageInfo")
    public List<MessageInfo> getMessageInfo()
    {
        return serivce.getMessageInfo();
    }
}
